package org.twdata.pipeline;

import org.springframework.beans.factory.*;

/**  Manages instances of pipeline stages by pooling them */
public class SimpleStageManager implements StageManager, BeanFactoryAware {

    private BeanFactory factory;
    
    /**
     *  Sets the beanFactory
     *
     *@param  factory  The new beanFactory value
     */
    public void setBeanFactory(BeanFactory factory) {
        this.factory = factory;
    }


    /**
     *  Gets the stage for the id from the pool.
     *
     *@param  id                     The id
     *@return                        The stage instance
     *@exception  PipelineException  If anything goes wrong
     */
    public Stage getStage(String id)
        throws PipelineException {
        try {
            Stage c = (Stage) factory.getBean(id);
            return c;
        } catch (Exception ex) {
            throw new PipelineException(ex);
        }
    }



    /**
     *  Recycles the pipeline stage then returns it to the pool
     *
     *@param  o                      The pipeline stage
     *@exception  PipelineException  If anything goes wrong
     */
    public void release(Stage o)
    throws PipelineException {}

}

